@echo off

:: 容器名称
set CONTAINER_NAME=DemoFlake

:: 本地路径和容器内路径
set LOCAL_PATH=C:\Users\jackiezheng\liushi\FindFakePlateVehicle-web
set CONTAINER_PATH=/opt/project

:: 检查容器是否已经存在
docker ps -a --filter "name=%CONTAINER_NAME%" --format "{{.Names}}" | findstr /i %CONTAINER_NAME% >nul
if %ERRORLEVEL% equ 0 (
    echo Starting existing Docker container %CONTAINER_NAME%...
    docker start %CONTAINER_NAME%
) else (
    echo Creating and starting new Docker container %CONTAINER_NAME%...
    docker run -d --name %CONTAINER_NAME% -p 8090:8090 -p 5000:5000 ^
        -v %LOCAL_PATH%:%CONTAINER_PATH% ^
        fakeplate-python3:latest /bin/bash -c "sleep infinity"
)

:: 等待 5 秒
echo Waiting for 5 seconds for the container to initialize...
timeout /t 5 /nobreak >nul

:: 启动第一个 Flask 服务并放入后台
echo Starting Flask services for /opt/project on port 5000...
docker exec %CONTAINER_NAME% /bin/bash -c "cd /opt/project && python3 start_server.py" >nul 2>&1 &

:: 等待 20 秒确保第一个服务启动
echo Waiting for 20 seconds for the first flask to initialize...
timeout /t 20 /nobreak >nul

:: 启动第二个 Flask 服务
echo Starting Flask services for /app/DarkNetAPI on port 8090...
docker exec %CONTAINER_NAME% /bin/bash -c "cd /app/DarkNetAPI && python3 start_server.py" >nul 2>&1 &

echo Flask services started.
